/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package vigas.calculos;

/**
 *
 * @author Gabriel
 */
public class VigaEmBalanco implements DiagramaEsforco{

    
    double E;			// módulo de elasticidade
    double I;			// momento de inércia
    double L;			// comprimento da viga
    int numPoints;		// número de pontos calculados
    int i;
    
    public double x[];          // distância da extremidade esquerda da viga
    public double v[];          // força cortante
    public double m[];		// momento
    public double y[];          // deflexão
    public double rr;		// reação no engaste
    public double mr;		// momento no engaste



    public  VigaEmBalanco(double E,double I,double L, int n)
    {
        this.E = E;
        this.I = I;
        this.L = L;
        this.numPoints=n;
        x = new double[n];
        inicializarVetores(numPoints);
        for (i=0;i<numPoints;++i)
                x[i]=(double)i*L/((double)numPoints-1.);

    }

    private void inicializarVetores(int n){
        				
        v = new double[n];
        m = new double[n];
        y = new double[n];

    }


    public void calcularEsforcosCargaDistribuida(double w1, double w2, double a, double b)
    {

        inicializarVetores(numPoints);
        
    	rr = w1*(b-a);
        mr = 0.5*rr*(a+b);

        for (i=0;i<numPoints;++i)
        {
            if (x[i]<(L-b))
            {
                v[(numPoints-1)-i] = 0;
    	    	m[(numPoints-1)-i] = 0;
                y[(numPoints-1)-i] = -rr/(24*E*I)*(4*(a*a+a*b+b*b)*(L-x[i])-a*a*a-a*b*b-a*a*b-b*b*b);
            }
            else
            {
                if (x[i]<(L-a))
                {
                    v[(numPoints-1)-i] = -rr/(b-a)*(x[i]-L+b);
                    m[(numPoints-1)-i] = -0.5*rr/(b-a)*Math.pow((x[i]-L+b),2);
                    y[(numPoints-1)-i] = -rr/(24*E*I)* ( 6*(a+b)*Math.pow(L-x[i],2) -4*Math.pow(L-x[i],3)
		    				+Math.pow(L-x[i]-a,4)/(b-a));
                }
                else
                {
                    v[(numPoints-1)-i] = -rr;
                    m[(numPoints-1)-i] = -0.5*rr*(2*x[i]-2*L+a+b);
                    y[(numPoints-1)-i] = -rr/(12*E*I)*(3*(a+b)*Math.pow(L-x[i],2)-2*Math.pow(L-x[i],3));
                }
            }
        }                
    }

    public void calcularEsforcosCargaConcentrada(double w, double a) {
        
        double b=L-a;
        rr = w;
        mr = w*a;
        inicializarVetores(numPoints);
        
        for (i=0;i<numPoints;++i)
        {
            if (x[i]<b)
            {
                v[(numPoints-1)-i] = 0.;
                m[(numPoints-1)-i] = 0.;
                y[(numPoints-1)-i] = -rr/(6.*E*I)*(-a*a*a+3.*a*a*L-3.*a*a*x[i]);
            }
            else
            {
                v[(numPoints-1)-i] = -rr;
                m[(numPoints-1)-i] = rr*(x[i]-b);
                y[(numPoints-1)-i] = -rr/(6*E*I)*(Math.pow(x[i]-b,3)-3*a*a*(x[i]-b)+2*a*a*a);
            }
        }

    }

    public void calcularEsforcosMomentoConcentrado(double mo, double a) {
        
        inicializarVetores(numPoints);
        double b=L-a;
        rr = 0;
        mr = -mo;

        
        for (i=0;i<numPoints;++i)
        {
            if (x[i]<b)
            {
                v[(numPoints-1)-i] = 0.;
                m[(numPoints-1)-i] = 0.;
                y[(numPoints-1)-i] = mo*a/(E*I)*(L-0.5*a-x[i]);
            }

            else
            {
                v[(numPoints-1)-i] = 0;
                m[(numPoints-1)-i] = -mo;
                y[(numPoints-1)-i] = 0.5*mo/(E*I)*(Math.pow(x[i]-L+a,2)-2*a*(x[i]-L+a)+a*a);
            }
        }
    }

     public double[] getM() {
        return m;
    }

    public double[] getV() {
        return v;
    }

}
